package net.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.kernel.KVisiteur;
import net.ko.http.objects.KRequest;
import net.ko.mapping.IMappingControl;

public class ControlAdmin implements IMappingControl {

	@Override
	public boolean isValid(HttpServletRequest request,
			HttpServletResponse response) {
		KVisiteur myUser=(KVisiteur) request.getSession().getAttribute("user");
		
		if(myUser!=null){
			if(myUser.getAdmin() == 1)
				return true;
		}
		return false;
	}

	@Override
	public void onInvalidControl(HttpServletRequest request,
			HttpServletResponse response) {
		try {
			KRequest.forward("/~/main.do", request, response,"url="+request.getServletPath());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public boolean beforeProcessAction(HttpServletRequest request,
			HttpServletResponse response) {
		return true;
	}
}
